package com.monitor.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.monitor.system.domain.vo.DataCenterVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.monitor.common.annotation.Log;
import com.monitor.common.core.controller.BaseController;
import com.monitor.common.core.domain.AjaxResult;
import com.monitor.common.enums.BusinessType;
import com.monitor.system.domain.DataCenter;
import com.monitor.system.service.IDataCenterService;
import com.monitor.common.utils.poi.ExcelUtil;
import com.monitor.common.core.page.TableDataInfo;

/**
 * 数据中心Controller
 * 
 * @author monitor
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/system/center")
public class DataCenterController extends BaseController
{
    @Autowired
    private IDataCenterService dataCenterService;

    /**
     * 查询数据中心列表
     */
    @ApiOperation("查询数据中心列表")
//    @PreAuthorize("@ss.hasPermi('system:center:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataCenter dataCenter)
    {
        startPage();
        List<DataCenter> list = dataCenterService.selectDataCenterList(dataCenter);
        return getDataTable(list);
    }

    /**
     * 导出数据中心列表
     */
    @ApiOperation("导出数据中心列表")
    @PreAuthorize("@ss.hasPermi('system:center:export')")
    @Log(title = "数据中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataCenter dataCenter)
    {
        List<DataCenter> list = dataCenterService.selectDataCenterList(dataCenter);
        ExcelUtil<DataCenter> util = new ExcelUtil<DataCenter>(DataCenter.class);
        util.exportExcel(response, list, "数据中心数据");
    }

    /**
     * 获取数据中心详细信息
     */
    @ApiOperation("获取数据中心详细信息")
    @PreAuthorize("@ss.hasPermi('system:center:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dataCenterService.selectDataCenterById(id));
    }

    /**
     * 新增数据中心
     */
    @ApiOperation("新增数据中心")
    @PreAuthorize("@ss.hasPermi('system:center:add')")
    @Log(title = "数据中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataCenter dataCenter)
    {
        return toAjax(dataCenterService.insertDataCenter(dataCenter));
    }

    /**
     * 修改数据中心
     */
    @ApiOperation("修改数据中心")
    @PreAuthorize("@ss.hasPermi('system:center:edit')")
    @Log(title = "数据中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataCenter dataCenter)
    {
        return toAjax(dataCenterService.updateDataCenter(dataCenter));
    }

    /**
     * 删除数据中心
     */
    @ApiOperation("删除数据中心")
    @PreAuthorize("@ss.hasPermi('system:center:remove')")
    @Log(title = "数据中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dataCenterService.deleteDataCenterByIds(ids));
    }

    /**
     * 查询数据中心列表
     */
    @ApiOperation("查询数据中心列表-仪表盘用")
    @GetMapping("/selectDataCenterInstrumentPanelList")
    public DataCenter selectDataCenterInstrumentPanelList(DataCenter dataCenter)
    {
        DataCenter data = dataCenterService.selectDataCenterInstrumentPanelList(dataCenter);
        return data;
    }

    /**
     * 查询数据中心列表
     */
    @ApiOperation("查询数据中心列表-链路拓扑用")
    @GetMapping("/linkTopologyList")
    public DataCenterVo linkTopologyList(DataCenter dataCenter)
    {
        DataCenterVo vo = dataCenterService.selectLinkTopologyList(dataCenter);
        return vo;
    }
}
